#ifndef CompareModeDelegate_H
#define CompareModeDelegate_H

#include <QtGui>

namespace Xps
{
	class CompareModeDelegate : public QItemDelegate
	{
		Q_OBJECT

	public:

		CompareModeDelegate::CompareModeDelegate(QObject *parent) : QItemDelegate(parent)
		{
		}

		QSize CompareModeDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const
		{
			return QSize(20,20);
		}

		QWidget *CompareModeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const
		{
			QComboBox *editor = new QComboBox(parent);

			editor->addItem("<");
			editor->addItem("<=");
			editor->addItem("==");
			editor->addItem(">=");
			editor->addItem(">");
			editor->setCurrentIndex(index.row());

			return editor;
		}

		void CompareModeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
		{
			int value = index.model()->data(index, Qt::EditRole).toInt();
			qDebug() << "Set editor data: " << " " << value;
			QComboBox *spinBox = static_cast<QComboBox*>(editor);
			spinBox->setCurrentIndex(value);//->setValue(value);*/
		}

		void CompareModeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
		{
			QComboBox *spinBox = static_cast<QComboBox*>(editor);
			int value = spinBox->currentIndex();
			model->setData(index, value, Qt::EditRole);
		}

		void CompareModeDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
		{
			editor->setGeometry(option.rect);
		}

	};
}

#endif